package com.leo.java8.datetime;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.Date;
import java.time.Instant;
import java.time.ZoneId;

public class NewFeaturesTester14 {

	public static void main(String args[]) {
		NewFeaturesTester14 tester = new NewFeaturesTester14();
		tester.applyBackwardCompatability();
	}

	public void applyBackwardCompatability() {

		// 获得当前日期并输出
		Date currentDate = new Date();
		System.out.println("Current date: " + currentDate);

		// 获得当前日期的实例（以毫秒的形式）
		Instant now = currentDate.toInstant();
		ZoneId currentZone = ZoneId.systemDefault();

		// 用ofInstant方法获得实例
		LocalDateTime localDateTime = LocalDateTime.ofInstant(now, currentZone);
		System.out.println("Local date: " + localDateTime);

		ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(now, currentZone);
		System.out.println("Zoned date: " + zonedDateTime);
	}
}